<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>签章控件</title>
        <script type="text/javascript" src="../internal.js"></script>
        <link rel="stylesheet" href="../../../bootstrap/bootstrap.css">
        <link rel="stylesheet" href="../../../bootstrap/bootstrap-responsive.css">
        <style type="text/css">
            *{color: #838383;margin: 0;padding: 0}
            html,body {font-size: 12px;overflow: hidden; }
            body {
                padding-left: 20px;padding-right: 20px;
            }
            label {
                display: inline;
            }
        </style>
    </head>
    <body>
        <table class="table table-striped table-bordered" style="margin-top:18px;margin-bottom: 0;">
            <tr>
                <th><span>控件名称</span><span class="label label-important">*</span></th>
                <th><span>控件类型</span><span class="label label-important">*</span></th>
            </tr>
            <tr>
                <td>
                    <input id="itemName" type="text" placeholder="必填项" size="20" />
                </td>
                <td>
                    <label><input type="checkbox" id="signType1" value="1" checked />盖章</label>
                    <label><input type="checkbox" id="signType2" onclick="fnSetSignColor()" value="2" checked />手写</label>
                </td>
            </tr>
            <tr>
                <th><span>验证锁定字段 (用,号分隔)</span></th>
                <th><span>手写颜色</span></th>
            </tr>
            <tr>
                <td>
                    <textarea id="itemList" style="width: 267px;height: 60px;" title="不填写则不验证"></textarea>
                </td>
                <td>
                    <select id="signColor" style="width:150px;">
                        <option style="background-color:red" value="0x0000FF">红色</option>
                        <option style="background-color:green" value="0x00FF00">绿色</option>
                        <option style="background-color:blue" value="0xFF0000">蓝色</option>
                        <option style="background-color:black" value="0x000000">黑色</option>
                        <option style="background-color:white" value="0xFFFFFF">白色</option>
                    </select>
                </td>
            </tr>
        </table>
        <script type="text/javascript">
            var oNode = null;
            window.onload = function() {
                //弹出窗口初始化函数，这里主要是判断是编辑多行文本框还是新增
                if( UE.plugins['sign'].editdom ){
                    oNode = UE.plugins['sign'].editdom;
                    $G('itemName').value = oNode.getAttribute('value');
                    $G('itemList').value = oNode.getAttribute('datafld');
                    if( oNode.getAttribute('sign_type') != null ) {
                        var aType = oNode.getAttribute('sign_type').split(",");
                        for( var i = 1; i <aType.length; i++ ) {
                            if( aType[i-1] == 1 ) {
                                $G("signType"+i).checked = true;
                            } else {
                                $G("signType"+i).checked = false;
                            }
                        }
                    }
                    if( oNode.getAttribute('sign_color') != null ) {
                        $G('signColor').value	= oNode.getAttribute('sign_color') ;
                    }
                }
                fnSetSignColor();
            }
            function fnSetSignColor(){
                if($G('signType2').checked == true){
                    $G('signColor').removeAttribute('disabled');
                } else {
                    $G('signColor').setAttribute('disabled','disabled');
                }
            }
            dialog.oncancel = function () {
                if( UE.plugins['sign'].editdom ) {
                    delete UE.plugins['sign'].editdom;
                }
            };
            dialog.onok = function (){
                if( $G('itemName').value == '' ){
                    alert('控件名称不能为空');
                    $G('itemName').focus();
                    return false;
                }
                if ( $G('signType1').checked == false && $G("signType2").checked == false ) {
                    alert("至少选择一个类型");
                    return false;
                }
                if( !oNode ) {
                    var sUrl =  parent.getItemUrl;
                    var nItemId = null;
                    ajax.request(sUrl, {timeout:60000,onsuccess:function (xhr) {
                            try {
                                nItemId = xhr.responseText;
                                oNode = document.createElement('img');
                                oNode.setAttribute('name', 'data_' + nItemId);
                                oNode.setAttribute('title', '签章控件:' + $G('itemName').value.replace("\"","&quot;"));
                                oNode.setAttribute('value', $G('itemName').value.replace("\"","&quot;"));
                                oNode.setAttribute('class', 'sign');
                                oNode.setAttribute('className', 'sign');
                                oNode.setAttribute('src', './static/image/form/sign.gif');
                                if($G('signType2').checked){
                                    oNode.setAttribute('sign_color',$G('signColor').value);
                                }
                                var sSignType = "";
                                if( $G("signType1").checked ) {
                                    sSignType += "1,";
                                } else {
                                    sSignType += "0,";
                                }
                                if( $G("signType2").checked ) {
                                    sSignType += "1,";
                                } else {
                                    sSignType += "0,";
                                }
                                oNode.setAttribute('sign_type',sSignType);
                                oNode.setAttribute('datafld',$G('itemList').value);
                                editor.execCommand('insertHtml',oNode.outerHTML);
                            } catch (e) {
                                return;
                            }
                        },
                        error:function () {
                            alert('Request TimeOut');
                        }
                    })
                } else {
                    oNode.setAttribute('title', '签章控件:' + $G('itemName').value.replace("\"","&quot;"));
                    oNode.setAttribute('value', $G('itemName').value.replace("\"","&quot;"));
                    oNode.setAttribute('datafld',$G('itemList').value);
                    var sSignType = "";
                    if( $G("signType1").checked ) {
                        sSignType += "1,";
                    } else {
                        sSignType += "0,";
                    }
                    if( $G("signType2").checked ) {
                        sSignType += "1,";
                        oNode.setAttribute('sign_color',$G('signColor').value);
                    } else {
                        sSignType += "0,";
                        oNode.removeAttribute('sign_color');
                    }
                    oNode.setAttribute('sign_type',sSignType);
                    delete UE.plugins['sign'].editdom; //使用后清空这个对象，变回新增模式
                }
            };
        </script>
    </body>
</html>
